package JavaSE.d1;

import java.util.Objects;

//实体类测试
public class Test1 {
    static class Tr{
        private double Chang;
        private double kuan;
        private double Gao;

        public Tr(double chang, double kuan, double gao) {
            Chang = chang;
            this.kuan = kuan;
            Gao = gao;
        }

        public Tr() {
        }

        public double getChang() {
            return Chang;
        }

        public void setChang(double chang) {
            Chang = chang;
        }

        public double getKuan() {
            return kuan;
        }

        public void setKuan(double kuan) {
            this.kuan = kuan;
        }

        public double getGao() {
            return Gao;
        }

        public void setGao(double gao) {
            Gao = gao;
        }

        @Override
        //重写equals
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Tr tr = (Tr) o;
            return Double.compare(tr.Chang, Chang) == 0 && Double.compare(tr.kuan, kuan) == 0 && Double.compare(tr.Gao, Gao) == 0;
        }

        @Override
        //重写hashCode
        public int hashCode() {
            return Objects.hash(Chang, kuan, Gao);
        }
    }

    public static void main(String[] args) {
        Tr tr0 = new Tr(14.5,10.2,5.5);
        Tr tr1 = new Tr(14.5,10.2,5.5);
        Tr tr3 = new Tr();//空

        System.out.println(tr0.equals(tr1));//重写了equals,比较的是属性
        System.out.println(tr0==tr1);//比较的是内存地址,都new对象,两个引用地址不一样
        System.out.println(tr0);//输出的地址,但因为重写了hashcode,转换的一样
        System.out.println(tr1);//输出的地址,但因为重写了hashcode,转换的一样
    }
}

